<template>
  <view v-if="shenheStatus == 0" class="commission">
    <view class="header-tabs">
      <u-tabs
        :list="tabList"
        :current="current"
        active-color="#FA230A"
        item-width="33.33%"
        @change="tabsChange"
        height="44"
        inactive-color="#262626"
      ></u-tabs>
    </view>
    <view class="contentBox">
      <view class="queryBox">
        <picker mode="date" fields="month" @change="changeDate">
          <view class="date">
            <text>{{ !queryDate ? $t("mdAdmin.queryTime") : queryDate }}</text>
            <text class="iconfont icon-arrow-down-filling"></text>
          </view>
        </picker>
        <text class="count"
          >{{ $t("shareholder.commi") }} ￥{{ total || 0 }}</text
        >
      </view>
      <view class="commissionList">
        <view class="commissionItem" v-for="(item, index) in list" :key="index">
          <view class="icon">
            <text class="iconfont">&#xe79e;</text>
          </view>
          <view class="commissionBox">
            <view class="info">
              <text>{{ item.profit_name }}</text>
              <text>{{ item.desc }}</text>
              <text
                >{{ $t("shareholder.getTime") }}：{{ item.created_at }}</text
              >
              <text v-if="item.is_send == 1"
                >{{ $t("shareholder.sendTime") }}：{{ item.send_time }}</text
              >
            </view>
            <view class="count">
              <text>+{{ item.money }}</text>

              <text v-if="item.is_refund == 1">已退款</text>
              <text v-else :class="item.is_send == 0 ? 'red' : ''">{{
                item.is_send == 0
                  ? $t("shareholder.noGet")
                  : $t("shareholder.getted")
              }}</text>
              <text class="red" v-if="item.trade_status == 1">{{
                $t("shop.cancled")
              }}</text>
            </view>
          </view>
        </view>
      </view>
      <view class="empty" style="padding-top: 50rpx">
        <u-empty mode="data" v-if="!list.length"></u-empty>
      </view>
    </view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from "@/components/shenhe/shenhe";
export default {
  components: { Shenhe },
  data() {
    return {
      tabList: [
        {
          name: this.$t("person.cashStatus1"),
          status: 0
        },
        {
          name: this.$t("shareholder.noGet"),
          status: 1
        },
        {
          name: this.$t("shareholder.getted"),
          status: 2
        }
      ],
      // 当前tab所处项
      current: 0,
      // 当前所在页面
      page: 1,
      // 是否加载完毕
      noMore: false,
      // 数据列表
      list: [],
      // 筛选时间
      queryDate: "",
      // 佣金总数
      total: "0.00",
      is_area: ""
    };
  },
  methods: {
    // 切换导航
    tabsChange(e) {
      if (e == this.current) return;
      this.page = 1;
      this.list = [];
      this.noMore = false;
      this.current = e;
      this.getList();
    },
    // 获取佣金列表
    async getList() {
      let status = this.current - 1;
      const res = await this.$allrequest.shareholder.profitList(
        {
          page: this.page,
          status,
          time: this.queryDate,
          is_area: this.is_area
        },
        true
      );
      if (res.code == 0) {
        this.page += 1;
        this.total = res.data.total;
        this.list = [...this.list, ...res.data.list];
        if (this.list.length >= res.data.row_count) {
          this.noMore = true;
        } else {
          this.noMore = false;
        }
      }
    },
    // 改变筛选时间
    changeDate(e) {
      this.queryDate = e.detail.value;
      this.page = 1;
      this.list = [];
      this.noMore = false;
      this.getList();
    }
  },
  onLoad(t) {
    if (t.status) {
      this.current = t.status - 0;
    }

    if (t.is_area) {
      this.is_area = "1";
    }
  },
  onShow() {
    this.page = 1;
    this.list = [];
    this.noMore = false;
    this.getList();
  },

  onReachBottom() {
    if (this.noMore) {
      return;
    }

    this.getList();
  }
};
</script>

<style lang="less" scoped>
.commission {
  min-height: 100vh;
  padding-top: 90rpx;
  background-color: #f2f2f2;
  font-family: PingFang SC;
  color: #262626;
}
.header-tabs {
  width: 100%;
  padding-top: 20rpx;
  height: 90rpx;
  // line-height: 90rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  z-index: 1000;
  left: 0;
}
.contentBox {
  padding-left: 30rpx;
  margin-top: 24rpx;
  background-color: #fff;
  .queryBox {
    padding: 30rpx 0;
    font-size: 26rpx;
    border-bottom: 1px solid #f8f8f8;
    .date {
      font-weight: 600;
      display: flex;
      align-items: center;
      margin-bottom: 12rpx;
      .iconfont {
        margin-left: 20rpx;
      }
    }
  }
  .commissionList {
    .commissionItem {
      padding-top: 30rpx;
      display: flex;
      .icon {
        width: 70rpx;
        height: 70rpx;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #fec121;
        .iconfont {
          font-size: 52rpx;
          color: #ffffff;
        }
      }
      .commissionBox {
        flex: auto;
        margin-left: 24rpx;
        padding: 0 30rpx 30rpx 0;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #f8f8f8;
        .info {
          display: flex;
          flex-direction: column;
          font-size: 24rpx;
          color: #8c8c8c;
          text:nth-child(1) {
            font-size: 28rpx;
            color: #262626;
            margin: 14rpx 0;
          }
          text:nth-child(2) {
            margin-bottom: 8rpx;
          }
          text:nth-child(3) {
            margin-bottom: 8rpx;
          }
        }
        .count {
          display: flex;
          align-items: flex-end;
          flex-direction: column;
          font-size: 26rpx;
          color: #8c8c8c;
          text:nth-child(1) {
            font-size: 36rpx;
            font-weight: 600;
            color: #262626;
            margin-bottom: 4rpx;
          }
          .red {
            color: #f0250e;
          }
        }
      }
    }
    .commissionItem:last-child {
      .commissionBox {
        border-bottom: none;
      }
    }
  }
}
</style>
